<?php
header("Content-Type: text/html; charset=iso-8859-1");
require('include.php');
if($user_id = check_cookie()){
	$user = new membre($user_id);
	if($user->id){
		$id = (!empty($_REQUEST['id'])) ? $_REQUEST['id'] : "";
		$equipe = (!empty($_REQUEST['equipe'])) ? $_REQUEST['equipe'] : "";
		if($id){
			$membre = new membre($id);
			if($membre){
				$output = $membre->vcard();
				$filename = str_replace("%20","_",$membre->prenom." ".$membre->nom);
				Header("Content-Disposition: attachment; filename=$filename.vcf");
				Header("Content-Length: ".strlen($output));
				header("Pragma: no-cache"); 
				header("Expires: 0");
				Header("Connection: close");
				Header("Content-Type: text/x-vCard; name=$filename");
				echo $output;
			}
			else error_log("no membre for vcard");
		}
		elseif($equipe){
			if($equipe == 'tous'){
				$q = "select id from membres where valide = 1 and fictif = 0 order by nom,prenom";
				$r = ExecRequete($q);
				$output = "";
				while($s = LigneSuivante($r)){
					$membre = new membre($s->id);
					$output .= $membre->vcard();
				}
				$filename = "VBCLL";
				Header("Content-Disposition: attachment; filename=$filename.vcf");
				Header("Content-Length: ".strlen($output));
				header("Pragma: no-cache"); 
				header("Expires: 0");
				Header("Connection: close");
				Header("Content-Type: text/x-vCard; name=$filename");
				echo $output;
			}
			else{
				$equipe = new equipe($equipe);
				if($equipe){
					$output = $equipe->vcard();
					$filename = str_replace("%20","_",$equipe->nom." : ".$equipe->nom_complet);
					Header("Content-Disposition: attachment; filename=$filename.vcf");
					Header("Content-Length: ".strlen($output));
					header("Pragma: no-cache"); 
					header("Expires: 0");
					Header("Connection: close");
					Header("Content-Type: text/x-vCard; name=$filename");
					echo $output;
				}
				else error_log("no equipe for vcard");							
			}
		}		
	}
}

?>
